package com.outdoor.server.controller.user;

import com.outdoor.common.result.Result;
import com.outdoor.pojo.dto.NodeCreateDTO;
import com.outdoor.pojo.entity.Track;
import com.outdoor.pojo.vo.TrackVO;
import com.outdoor.server.service.TrackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/track")
@Slf4j
public class TrackController {

    @Autowired
    private TrackService trackService;

    /**
     * 开始记录轨迹
     * @param uid
     * @return
     */
    @PostMapping("/start")
    public Result<Long> startTrack(@RequestParam Long uid) {
        log.info("用戶 {} 开始记录轨迹: {}", uid);
        Long trackId = trackService.startTrack(uid);
        return Result.success(trackId);
    }

    /**
     * 添加轨迹节点
     * @param nodeCreateDTO
     * @return
     */
    @PostMapping("/addNode")
    public Result addNode(@RequestBody NodeCreateDTO nodeCreateDTO) {
        log.info("添加轨迹节点: {}", nodeCreateDTO);
        trackService.addNode(nodeCreateDTO);
        return Result.success();
    }

    /**
     * 结束记录轨迹
     * @param trackId
     * @return
     * @throws Exception
     */
    @PostMapping("/end/{trackId}")
    public Result endTrack(@PathVariable Long trackId) {
        log.info("结束轨迹: {}", trackId);
        trackService.endTrack(trackId);
        return Result.success();
    }

    /**
     * 获取用户所有轨迹
     * @return
     */
    @GetMapping("/all")
    public Result<List<Track>> getAllTrack(@RequestParam Long uid) {
        log.info("获取用户所有轨迹: {}", uid);
        List<Track> tracks = trackService.getAllTrack(uid);
        return Result.success(tracks);
    }
    /**
     * 获取轨迹详情
     * @param trackId
     * @return
     */
    @GetMapping("/{trackId}")
    public Result<TrackVO> getTrackDetail(@PathVariable Long trackId) {
        log.info("获取轨迹详情: {}", trackId);
        TrackVO trackVO = trackService.getTrackDetail(trackId);
        return Result.success(trackVO);
        }
} 